// 1- ip
//    本机：http://127.0.0.1:8090
//    本机：http://localhost:8090
//    局域网：http://192.168.46.23:8090
// 2- hosts:   27.0.0.1  zhangpeiyue.com
//    http://zhangpeiyue.com:8090
const http = require("http");
const url = require("url");
const fs = require("fs");
const path = require("path");
const server = http.createServer((req,res)=>{
	const {pathname} = url.parse(req.url);
	res.setHeader("Content-Type","text/html;charset=utf-8");
	if(pathname === "/"){
		fs.readFile(path.join(__dirname,"./html/weibo.html"),(err,result)=>{
			res.end(result);
		})
	}else if(pathname === "/style/weibo.css"){
		res.setHeader("Content-Type","text/css;charset=utf-8");
		fs.readFile(path.join(__dirname,"./html/style/weibo.css"),(err,result)=>{
			res.end(result);
		})
	}else if(pathname === "/img/takeSbmComment.png"){
		res.setHeader("Content-Type","image/png;charset=utf-8");
		fs.readFile(path.join(__dirname,"./html/img/takeSbmComment.png"),(err,result)=>{
			res.end(result);
		})
	}else if(pathname === "/img/icons.png"){
		res.setHeader("Content-Type","image/png;charset=utf-8");
		fs.readFile(path.join(__dirname,"./html/img/icons.png"),(err,result)=>{
			res.end(result);
		})
	}else res.end("404，不存在");
});
server.listen(8090,()=>{
	console.log("success");
})